package eu.log;


public class SimpleDeamon implements LogDaemon{
	
	private Storage storage=StorageFactory.getDefaultStorage();
	
	/**
	 * 只有包内可调用此构造函数
	 */
	SimpleDeamon(){}
	
	@Override
	public void debug(String clientIdentity, String event) {
		takeLog(clientIdentity, event, Rank.DEBUG);
	}

	@Override
	public void info(String clientIdentity, String event) {
		takeLog(clientIdentity, event, Rank.INFO);
	}

	@Override
	public void notice(String clientIdentity, String event) {
		takeLog(clientIdentity, event, Rank.NOTICE);
	}

	@Override
	public void warn(String clientIdentity, String event) {
		takeLog(clientIdentity, event, Rank.WARN);
	}

	@Override
	public void error(String clientIdentity, String event) {
		takeLog(clientIdentity, event, Rank.ERROR);
	}

	@Override
	public void deadly(String clientIdentity, String event) {
		takeLog(clientIdentity, event, Rank.DEADLY);
	}

	@Override
	public void alert(String clientIdentity, String event) {
		takeLog(clientIdentity, event, Rank.ALERT);
	}

	private void takeLog(String clientIdentity, String event,Rank rank){
		Log log=storage.newLog(clientIdentity, event, System.currentTimeMillis(),rank);
		storage.add(log);
		Storage rs=StorageFactory.getStorage(rank);
		if(rs!=null){
			rs.add(log);
		}
	}

	@Override
	public void debug(String event) {
		takeLog(null, event, Rank.DEBUG);
	}

	@Override
	public void info(String event) {
		takeLog(null, event, Rank.INFO);
	}

	@Override
	public void notice( String event) {
		takeLog(null, event, Rank.NOTICE);
	}

	@Override
	public void warn( String event) {
		takeLog(null, event, Rank.WARN);
	}

	@Override
	public void error( String event) {
		takeLog(null, event, Rank.ERROR);
	}

	@Override
	public void deadly( String event) {
		takeLog(null, event, Rank.DEADLY);
	}

	@Override
	public void alert( String event) {
		takeLog(null, event, Rank.ALERT);
	}

	@Override
	public QueryInterface getQueryFace() {
		return new QueryFace(storage);
	}
}
